import { useIntersectionObserver } from '@vueuse/core'

export default function lazy(el: any, binding: any) {
	const { stop } = useIntersectionObserver(el, ([{ isIntersecting }]) => {
		el.src = binding.value.defaultImg
		if (isIntersecting) {
			el.onerror = function () {
				el.src = binding.value.defaultImg
			}
			el.src = binding.value.src
			stop()
		}
	})
}
